package com.leetcode.August;

/**
 * @Description: 14. 最长公共前缀
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-21 12:40
 */
public class LC14最长公共前缀 {
    public String longestCommonPrefix(String[] strs) {
        if (strs.length == 0)return "";
        String s = strs[0];
        for (String str : strs) {
           while (!str.startsWith(s)){
               if (s.length() == 0) return "";
               s = s.substring(0, s.length() - 1);
           }
        }
        return s;
    }
}
